package com.sx.manage.controller.helps;

import java.io.IOException;

import javax.annotation.Resource;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sx.common.util.json.JackJsonUtil;
import com.sx.manage.controller.base.MBaseController;
import com.sx.manage.service.helps.IMSysIntroduceService;
import com.sx.manage.servlet.ViewAndModel;
import com.sx.model.manage.mybatis.form.helps.MSysIntroduceForm;
import com.sx.model.manage.mybatis.vo.helps.MSysIntroduceVO;
import com.sx.model.manage.mybatis.vo.result.ResultBooleanVO;
import com.sx.model.manage.mybatis.vo.result.ResultListVO;
import com.sx.model.manage.mybatis.vo.result.ResultObjectVO;

/**
 * 关于我们
 * 
 * @author zwm
 *
 */
@Controller
@RequestMapping("/sysIntroduce")
public class MSysIntroduceController extends MBaseController {

	private Logger _log = LoggerFactory.getLogger(this.getClass());
	@Resource(name = "sysIntroduceServiceImpl")
	private IMSysIntroduceService mSysIntroduceServiceImpl;

	@RequestMapping(value = "introduce_index") // add_view_introduce
	public ViewAndModel add_sysIntroduce_view() {
		ViewAndModel viewAndModel = new ViewAndModel(request, cache);
		// 修改ftl页面名称
		viewAndModel.setViewName("help/aboutUs/addAbout");
		viewAndModel.addObject("msysIntroduceInfoVO", new MSysIntroduceVO());
		return viewAndModel;
	}

	@RequestMapping(value = "introduce_eidt") // eidt_introduce
	@ResponseBody
	public ResultBooleanVO add_sysIntroduce(HttpServletRequest request, HttpServletResponse response){
		if (null == request) {
			return new ResultBooleanVO("sj.m.common.add.error");
		}
		String request_message = extract_param_from_request(request);
		if (null == request_message || "".equals(request_message)) {
			return new ResultBooleanVO("sj.m.common.add.error");
		}
		MSysIntroduceForm form =  JackJsonUtil.jsonToJavaBean(request_message, MSysIntroduceForm.class);
		_log.debug("添加系统操作日志：MSysIntroduceController===add_sysIntroduceInfo==formJson=" + JackJsonUtil.objToJson(form));
		if (null == form) {
			return new ResultBooleanVO("sj.m.common.add.error");
		}
		if (null == form.getId()) {
			return mSysIntroduceServiceImpl.addMsysIntroduce(form, this.loginConsumer());
		}
		return mSysIntroduceServiceImpl.editMsysIntroduce(form, this.loginConsumer());
	}

	@RequestMapping("/introduce_byid/{id}")
	@ResponseBody
	public ViewAndModel query_viewSysIntroduce(MSysIntroduceForm form){
		_log.debug("添加系统操作日志：MSysIntroduceController===query_viewSysIntroduce==formJson=" + JackJsonUtil.objToJson(form));
		ViewAndModel viewAndModel = new ViewAndModel(request, cache);
		ResultObjectVO<MSysIntroduceVO> ROVO = mSysIntroduceServiceImpl.search_byId(form);
		MSysIntroduceVO vo = ROVO.getObjVo();
		viewAndModel.setViewName("help/aboutUs/addAbout");
		viewAndModel.addObject("msysIntroduceInfoVO", vo);
		return viewAndModel;
	}

	/**
	 * 查询列表视图
	 * 
	 * @return
	 */
	@RequestMapping("/search_view_introduce")
	public ViewAndModel search_ViewSysIntroduce(){
		ViewAndModel viewAndModel = new ViewAndModel(request, cache);
		// 如需在添加页需要加载元素在此处增加 
		viewAndModel.setViewName("help/aboutUs/aboutUs");// 修改fitly页面名称
		return viewAndModel;
	}

	/**
	 * 查询 数据集合
	 * 
	 * @param form
	 * @return
	 * @throws ServletException
	 * @throws IOException
	 */
	@RequestMapping("/search_page_introduce")
	@ResponseBody
	public ResultListVO<MSysIntroduceVO> search_SysIntroduce(MSysIntroduceForm form){
		_log.debug("添加系统操作日志：MSysIntroduceController===search_SysIntroduce==formJson=" + JackJsonUtil.objToJson(form));
		return this.mSysIntroduceServiceImpl.searchMsysIntroduce(form);
	}

	/**
	 * 删除 根据ID查询
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws ServletException
	 * @throws IOException
	 */
	@RequestMapping("/introduce_del") // del_introduce
	@ResponseBody
	public ResultBooleanVO del_sysIntroduce(HttpServletRequest request, HttpServletResponse response){
		String request_message = extract_param_from_request(request);
		if (null == request_message || "".equals(request_message)) {
			return new ResultBooleanVO("sj.m.common.add.error");
		}
		MSysIntroduceForm form = JackJsonUtil.jsonToJavaBean(request_message, MSysIntroduceForm.class);
		_log.debug("添加系统操作日志：MSysIntroduceController===del_sysIntroduce==formJson=" + JackJsonUtil.objToJson(form));
		if (null == form) {
			return new ResultBooleanVO("sj.m.common.del.error");
		}
		return this.mSysIntroduceServiceImpl.delMsysIntroduce(form, this.loginConsumer());
	}

}
